import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/index")
public class Index extends HelloServlet{
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //先验证用户的登陆状态
        //如果未登录就要求用户先登录，如果登陆了就显示欢迎xxx
        if(req.getSession(false) == null){
            //如果为null说明没有session对象
            //自然就是没有登录
            resp.setContentType("text/html;charset=utf8");
            resp.getWriter().write("请先登录");
        }else {
            resp.setContentType("text/html;charset=utf8");
            resp.getWriter().write("欢迎用户"+ req.getSession().getAttribute("user") + "登录");
            resp.getWriter().write("上次登录时间:"+req.getSession().getAttribute("time"));

        }
    }
}
